var Stomp = require("stomp-client");
const mongoose = require("mongoose");
var Merchant = mongoose.model("merchant");
var destination = '/queue/ita_p4_score_mq';
var client = new Stomp('10.222.232.152', 61613, '', '');

client.connect(function (sessionId) {
//???
    client.subscribe(destination, function (body, headers) {
        console.log('score jms c2a: mId+#+stark');
        console.log("Headers:" + headers);
        console.log("Body:" + body);
        var str = body.split("#");
        //var merchant = new Merchant();
        //merchant.mId = str[0];
        //merchant.mScore = str[1];
        Merchant.findOne({mId: str[0]}, function (err, merchant) {
            merchant.mScore = str[1];
            merchant.save(function (err) {
                console.log('in' + merchant.mId);
                if (err) {
                    console.log("error: score jms findOne");
                }
            })
        });
    });

//???
// client.publisher(destination,'john');
});